#include "C:\fltk-1.3.2\FL\Fl.H"
#include "C:\fltk-1.3.2\FL\Fl_Window.H"
#include "C:\fltk-1.3.2\FL\Fl_Button.H"
#include "C:\fltk-1.3.2\FL\Fl_Input.H"
#include "C:\fltk-1.3.2\FL\Fl_Output.H"
#include "windows.h"
#include <iostream>
#include <ctime>
#include <vector>
#include <map>

using namespace std;

//add list box here
Fl_Input *hostname_in;
Fl_Input *port_in;
Fl_Input *username_in;
Fl_Input *keypath_in;
Fl_Input *command_in;
Fl_Button *go_btn;
Fl_Button *end_btn;
string build_command;
string space = " ";
string opt_ssh = "-ssh ";
string opt_key;
string opt_port;
string opt_at;
const char* command;

void execute(Fl_Widget *o, void*) {
    if (port_in->size() > 0) {
        opt_port = "-P ";
    }
    if (keypath_in->size() > 0) {
        opt_key = "-i ";
    }
    if (username_in->size() > 0) {
        opt_at = "@";
    }

    build_command = opt_ssh + space + opt_key + keypath_in->value() + space + username_in->value() + opt_at + hostname_in->value() + space + opt_port + port_in->value();
    ShellExecute(0,
                "open",
                "C:\\ssh\\putty.exe",
                build_command.c_str(),
                0,
                1);
}

void quit(Fl_Widget *o, void*) {
    exit(1);
}

void make_input_window() {
        Fl_Window *win = new Fl_Window(300, 180, "MojoHost PuTTY Interface v0.1 - FLTK Edition");
        win->begin();
                hostname_in = new Fl_Input(110, 20, 140, 20, "Server");
                port_in = new Fl_Input(110, 40, 140, 20, "Port");
                username_in = new Fl_Input(110, 60, 140, 20, "Username");
                keypath_in = new Fl_Input(110, 80, 140, 20, "Key");
                command_in = new Fl_Input(110, 100, 140, 20, "Command");
                Fl_Button *go_btn = new Fl_Button(90, 135, 50, 30, "Go");
                Fl_Button *end_btn = new Fl_Button(140, 135, 50, 30, "Quit");
                go_btn->callback(execute);
                end_btn->callback(quit);
        win->end();
        win->show();
}



int main() {
        make_input_window();
        return(Fl::run());
}
